package com.aw.baselib.util;

/**
 * @author : hzw
 * @date : 2020/3/18
 */
public class UserUtil {

    public static void saveAccount(String account) {
        SPUtils.put("account", account);
    }

    public static String getAccount() {
        return (String) SPUtils.get("account", "");
    }

    public static void savePwd(String pwd) {
        SPUtils.put("pwd", pwd);
    }

    public static String getPwd() {
        return (String) SPUtils.get("pwd", "");
    }

    public static void saveVin(String vin) {
        SPUtils.put("vin", vin);
    }

    public static String getVin() {
        return (String) SPUtils.get("vin", "");
    }

    public static void saveUserLat(String lat) {
        SPUtils.put("userLat", lat);
    }

    public static String getUserLat() {
        //默认天安门纬度
        return (String) SPUtils.get("userLat", "39.915119");
    }

    public static void saveUserLng(String lng) {
        SPUtils.put("userLng", lng);
    }

    public static String getUserLng() {
        //默认天安门经度
        return (String) SPUtils.get("userLng", "116.403963");
    }

    public static void saveUserAddress(String address) {
        SPUtils.put("userAddress", address);
    }

    public static String getUserAddress() {
        return (String) SPUtils.get("userAddress", "");
    }

    public static void savePhone(String param) {
        if(AwDataUtil.isEmpty(param)) {
            param = "13921131093";
        }
        SPUtils.put("phone", param);
    }

    public static String getPhone() {
        return (String) SPUtils.get("phone", "13921131093");
    }


    public static void clearUser() {
        SPUtils.put("user", "");
        SPUtils.put("token", "");
        SPUtils.put("warehouse", "");
    }

    public static void saveToken(String token) {
        SPUtils.put("token", token);
    }

    public static String getToken() {
        if(!AwDataUtil.isEmpty((String) SPUtils.get("token", ""))) {
            return "Bearer " + SPUtils.get("token", "");
        } else {
            return "";
        }
    }

    public static void setFirstUse(boolean isFirstUse) {
        SPUtils.put("isFirstUse", isFirstUse);
    }

    public static boolean isFirstUse() {
        return (Boolean) SPUtils.get("isFirstUse", true);
    }

    public static void setIsAgreePrivacy(boolean isFirstUse) {
        SPUtils.put("isAgreePrivacy", isFirstUse);
    }

    public static boolean isAgreePrivacy() {
        return (Boolean) SPUtils.get("isAgreePrivacy", false);
    }


    /**
     * 登录记住密码
     * @param phone
     * @param password
     */
    public static void loginRememberToSave(String phone, String password, boolean isRemember) {
        SPUtils.put("rememberPassword", isRemember);
        SPUtils.put("phone", phone);
        if(isRemember) {
            SPUtils.put("password", password);
        }
    }

    /**
     * 退出登录等清除本地保存的记录.
     */
    public static void cleanLocalSaveAccountAndPwd() {
        SPUtils.put("phone", "");
        SPUtils.put("password", "");
    }

    public static String getRememberPhone() {
        return (String) SPUtils.get("phone", "");
    }

    public static String getRememberPwd() {
        return (String) SPUtils.get("password", "");
    }

    public static boolean isRemeberLogin() {
        return (boolean) SPUtils.get("rememberPassword", false);
    }

}
